<template>
  <div>
    <h1>登录中心</h1>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td align="right">账号</td>
          <td>
            <input type="text" v-model="queryInfo.userName">
          </td>
        </tr>

        <tr>
          <td align="right">密码</td>
          <td>
            <input type="password" v-model="queryInfo.userPwd">
          </td>
        </tr>

        <tr>
          <td align="right"></td>
          <td>
            <input type="button" value="登录" class="btn btn-primary" @click="Login">
          </td>
        </tr>

      </tbody>
    </table>



  </div>
</template>


<script setup lang="ts">

import { ref, reactive } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';


import{UseUserStore}from '../stores/user'
const UserStore=UseUserStore();
//创建一个路由器：实现页面跳转
const router=useRouter();


let queryInfo = reactive({
  userName: '',
  userPwd: '',
})



const Login = () => {
  //1.判断有效性
  if (queryInfo.userName == "") {
    alert('用户名不能为空')
    return;
  }
  if (queryInfo.userPwd == "") {
    alert('密码不能为空');
    return;
  }
  //2.发送网络请求去后端验证账号和秘密在数据库中是否存在
  axios({
    method:'get',
    url:'/api/Admin/AdminLogin',
    params:queryInfo,
  })
  .then(res=>{
      console.log(res);
      if(res.data.Id==-1){
        alert('账号不存在');
        return;
      }
     else  if(res.data.Id==-2){
          alert('密码错误');
          return;
      }
      else if(res.data.Id>0){
        alert('登录成功');
        UserStore.userinfo=res.data
       router.push('/MemberLevelList');
      }
      
  })
 .catch(err=>{
  console.log(err)
 })
  



}

</script>









<style scoped></style>